package com.ceba.test.modules.admin.service;

import java.util.ArrayList;
import java.util.List;

import com.ceba.test.base.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ceba.test.base.configs.CebaPathUtil;
import com.ceba.base.web.service.IBaseService;
import com.ceba.test.modules.admin.dao.TemplateWordDao;
import com.ceba.test.modules.admin.entity.TemplateWord;

import abc.ID;
import abc.data.DataRow;
import abc.data.DataTable;
import abc.data.store.IStore;
import abc.data.store.StoreManager;
import abc.object.XObject;

public class TemplateWordService extends IBaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(TemplateWordService.class);
	private TemplateWordDao templateWordDao;
	

	public  DataTable queryMergeAu(String userID) throws Exception{

		return templateWordDao.queryMergeAu(userID);

	}

	/**
	 * 获取所有
	 * @return
	 * @throws Exception
	 */
	public  DataTable getDataTable() throws Exception{
		return templateWordDao.getDataTable();

	}
	
	/**
	 * 新增
	 * @param tw
	 * @return
	 */
	public boolean add(TemplateWord tw){
		IStore store = StoreManager.create("templates_word");
		XObject object = new XObject("ID",ID.getGuid());
		object.put("WORD_NAME", tw.getWordName());
		object.put("WORD_PATH", tw.getWordPath());
		object.put("WORD_GENERATE_NAME", tw.getWordGeneratrName());
		object.put("WORD_VIRTUAL_PATH", tw.getWordVirtualPath());

		if (!StringUtil.isEmptyString(tw.getStorageAddressId())) {
			object.put("STORAGE_ADDRESS_ID", tw.getStorageAddressId());
		}

		object.setUpdateUser();
		object.setUpdateTime();
		boolean success=  templateWordDao.add(store,object);
		return success;
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	public boolean delete(String id){
		return templateWordDao.delete(id);
	}

	/**
	 * 修改
	 * @param tw
	 * @return
	 */
	public boolean modify(TemplateWord tw){
		return templateWordDao.modify(tw);
	}
	
	public  TemplateWord getTemplateWordById(String ID)throws Exception{
		TemplateWord tw = new TemplateWord();
		DataTable dt = templateWordDao.getDataTableById(ID);
		if(dt !=null && dt.getRowCount()>0){
			DataRow dr = dt.getRow(0);
			tw.setId(ID);
			tw.setWordName(dr.getString("WORD_NAME"));
			//tw.setWordPath(dr.getString("WORD_PATH"));
			tw.setWordGeneratrName(dr.getString("WORD_GENERATE_NAME"));
			tw.setWordVirtualPath(dr.getString("WORD_VIRTUAL_PATH"));
			tw.setWordPath(tw.getWordVirtualPath());
			return tw;
		}else{
			return null;
		}
		
	}
	
	public DataTable getTemplateWordList() throws Exception{
		DataTable dt = templateWordDao.getDataTable();
		return dt;
		
	}

	
	
	public TemplateWordDao getTemplateWordDao() {
		return templateWordDao;
	}

	public void setTemplateWordDao(TemplateWordDao templateWordDao) {
		this.templateWordDao = templateWordDao;
	}
	
	
	/**
	 * 获取签章报告模板的第一条记录
	 * @return
	 * @throws Exception
	 */
	public TemplateWord getTemplateFilePath(){
		return templateWordDao.getTemplateFilePath();
	}
	
	/**
	 * 获取签章报告模板的第一条记录
	 * @return
	 * @throws Exception
	 */
	public TemplateWord getTemplateIdFilePath(String fielId){
		return templateWordDao.getTemplateIdFilePath(fielId);
	}
	
	
}
